package com.laikan.reader.bookfriend.fragment.impl;

import android.os.Bundle;
import android.view.View;

import com.laikan.library.httpvolley.helper.VolleyErrorHandler;
import com.laikan.library.httpvolley.response.HttpResponse;
import com.laikan.reader.R;
import com.laikan.reader.bookfriend.adapter.BaseListAdapter;
import com.laikan.reader.bookfriend.adapter.impl.FunsAdapter;
import com.laikan.reader.bookfriend.entity.PageFansBean;
import com.laikan.reader.bookfriend.fragment.BaseListFragment;
import com.laikan.reader.bookfriend.requester.SimpleRequestListener;
import com.laikan.reader.bookfriend.requester.AutherRequester;
import com.laikan.reader.bookfriend.utils.Constant;
import com.socks.library.KLog;

/**
 * Created by lingyt on 2016/11/17.
 * 粉丝页
 */
public class FunsFragment extends BaseListFragment {


    private String autherId;

    public void setAutherId(String autherId) {
        this.autherId = autherId;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (mBundle != null) {
            String userId = mBundle.getString(Constant.USER_ID,"");
            setAutherId(userId);
        }
    }

    @Override
    protected void setListener() {
        if (mAdapter instanceof FunsAdapter){

        }
    }

    @Override
    protected void onClickEvent(View view) {

    }

    @Override
    protected BaseListAdapter getAdapter() {
        return new FunsAdapter(getActivity(), R.layout.view_item_fans,this);
    }

    @Override
    protected void loadData(int pageNo) {
        KLog.w(args,"load Data:开始加载第 "+pageNo+" 页数据");
        String authorId = getAuthorId();
        AutherRequester.requestFunsList(pageNo,authorId,mCallback);
    }

    private SimpleRequestListener mCallback = new SimpleRequestListener(this){

        @Override
        public void onSuccess(HttpResponse httpResponse) {
            PageFansBean pageFansBean = mGson.fromJson(httpResponse.responseContent,PageFansBean.class);
            setFragmentData(pageFansBean);
        }

        @Override
        public void onError(VolleyErrorHandler errorHandler) {
            onRequestDataError();
        }
    };

    private String getAuthorId() {
//    test    return "6314266";
        return this.autherId;
    }

    @Override
    public void refreshFragmentData() {
        PageFansBean bean = (PageFansBean) getFragmentData();
        mState = checkData(bean.data.list);
        showData(bean.data.list);
    }

}
